﻿using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace TestsModel.Data
{
    public class TestData
    {
        public List<CheckTest> CheckTestQuestions { get; set; }
        public List<RadioTest> RadioTestQuestions { get; set; }
        public List<InputTest> InputTestQuestions { get; set; }
        public List<MatchTest> MatchTestQuestions { get; set; }
        public List<FillTest> FillTestQuestions { get; set; }

        public TestData()
        {
            CheckTestQuestions = new List<CheckTest>();
            RadioTestQuestions = new List<RadioTest>();
            InputTestQuestions = new List<InputTest>();
            MatchTestQuestions = new List<MatchTest>();
            FillTestQuestions = new List<FillTest>();
        }

        public TestData ClearAnswers()
        {
            CheckTestQuestions.ForEach(question => question.Statements.ForEach(statement => statement.Item2 = false));
            RadioTestQuestions.ForEach(question => question.Answer = -1);
            InputTestQuestions.ForEach(question => question.Answer = string.Empty);
            MatchTestQuestions.ForEach(question => question.LeftStatements.ForEach(statement => statement.Item2 = -1));
            FillTestQuestions.ForEach(question => question.Text = Regex.Replace(question.Text,
                string.Format("{0}([0-9]*){1}", FillTest.StartingPlaceholder, FillTest.EndingPlaceholder),
                match => FillTest.StartingPlaceholder + FillTest.EndingPlaceholder));

            return this;
        }
    }
}